define(function(require,exports,module){
	var Grid = require("grid");
	var service = require("../store/roomTypeSvc");
	var constant = require("../constant/roomTypeProps");
	
	module.exports = {
		initComponent: function(widget){
			var grid = new Grid({
				parentNode: ".J-grid",
				autoRender: false,
				model: {
					url: "api/roomtype/query",
					params: function(){
						return {
							"servicePoint.pkServicePoint" : widget.get("subnav").getValue("svcPoint"),
							"orderString":"code:DESC",
							fetchProperties: constant.gridFetchProperties
						};
					},
					columns: [{
						name: "code",
						label: "房型编号"
					},{
						name: "name",
						label: "房型名称"
					},{
						name: "orgBuildings",
						label: "所属楼宇",
						format: function(value,row){
							var ret = "";
							for(var i=0;i<value.length;i++){
								ret += "<div>"+value[i].name+"</div>";
							}
							return ret;
						}
					},{
						name: "operate",
						label: "操作",
						format: "button",
						formatparams: [{
							id: "edit",
							icon: "icon-edit",
							handler: function(index,data,rowEL){
								var form = widget.get("form");
								form.reset();
								form.setData(data);
								if(data.attachmentUrl!=null){
									var attachmentUrl = data.attachmentUrl.split(";");
									for(var i=1;i<7;i++){
										form.download("attachmentUrl" + (i),
												"api/attachment/roomtype/"+data.pkRoomType + "/" + (i));
//										form.$("div[el-data-component=attachmentUrl"+i+"]")
//											.find("input").eq(0).val(attachmentUrl[i-1]);
									}
								}
								$(".input-group :button").addClass('btn btn-theme');
								widget.toCard();
							}
						},{
							id: "remove",
							icon: "icon-remove",
							handler: function(index,data,rowEL){
								service.del(data.pkRoomType,function(){
									widget.get("grid").refresh();
								});
							}
						}]
					}]
				}
			});
			widget.set("grid",grid);
		}
	};
});